package controllers;

import models.*;
/**
 * Created with IntelliJ IDEA.
 * User: Daniel
 * Date: 11/07/12
 * Time: 12:33 PM
 * To change this template use File | Settings | File Templates.
 */
public class Security extends Secure.Security{

    static boolean authenticate(String username, String password) {
        return Hidusuario.connect(username, password) != null;
    }

    static boolean check(String profile) {

        if ("admin".equals(profile)) {
            Hidusuario hidusuario = Hidusuario.find("byUsuuser", connected()).first();
            if (hidusuario != null) {
                if(hidusuario.getHidperfil().getPerfnom().equals("usuario"))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        } else if ("user".equals(profile)) {
            return connected().equals("user");
        }
        return false;
    }
}
